define(["jquery", "easy-admin","xm-select"], function ($, ea) {


    var ids =$("#ids").val();
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'mall.door/index?id='+ids,
        add_url: 'mall.door/add?id='+ids,
        edit_url: 'mall.door/edit',
        delete_url: 'mall.door/delete',
        export_url: 'mall.door/export',
        modify_url: 'mall.door/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                height:'full-50',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id',search: false},
                    {field: 'title', title: '门店名称'},
                    {field: 'manager_id', title: '所属商家名称',search: 'select',selectList: managerlist},
                    {field: 'realname', title: '联系人',search: false},
                    {field: 'mobile', title: '联系电话'},
                    {field: 'location', title: '门店地址'},
                    {field: 'status', search: 'select', selectList: ["禁用","启用"], title: '状态', templet: ea.table.switch},
                    {field: 'create_time', title: '添加时间',search: 'range'},
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
            });
            ea.listen();
        },
        add: function () {

            var demo1 = xmSelect.render({
                el: '#address',
                on: function (data) {
                    var arr = data.arr;
                    if (arr.length > 0) {
                        for (let i = 0; i < arr.length; i++) {
                            $("#addressstr").val(arr[i].value);
                            $("#namestr").val(arr[i].name);
                        }
                    }
                },
                radio: true,
                autoRow: true,
                toolbar: { show: true },
                filterable: true,
                remoteSearch: true,
                remoteMethod: function(val, cb, show){
                    var county =$("#county").val();
                    val =county+''+val;
                    $.ajax({
                        type: "GET",
                        url: "/admin/mall.door/getRegionSearchResult",
                        data: {keyword: val},
                        dataType: "json",
                        success: function (data) {
                            console.log(data);
                            cb(data.data.location);
                        }
                    })
                }
            })
            ea.listen();
        },
        edit: function () {
            var demo1 = xmSelect.render({
                el: '#address',
                on: function (data) {
                    var arr = data.arr;
                    if (arr.length > 0) {
                        for (let i = 0; i < arr.length; i++) {
                            $("#addressstr").val(arr[i].value);
                            $("#namestr").val(arr[i].name);
                        }
                    }
                },
                radio: true,
                autoRow: true,
                toolbar: { show: true },
                filterable: true,
                remoteSearch: true,

                remoteMethod: function(val, cb, show){

                    var county =$("#county").val();
                    val =county+''+val;
                    $.ajax({
                        type: "GET",
                        url: "/admin/mall.door/getRegionSearchResult",
                        data: {keyword: val},
                        dataType: "json",
                        success: function (data) {
                            console.log(data);
                            cb(data.data.location);
                        }
                    })
                }
            })
            demo1.setValue([
                {name: $("#namestr").val(), value: $("#addressstr").val()},
            ])
            ea.listen();
        },
    };
    return Controller;
});